import 'package:flutter/material.dart';
import 'package:x3_base_package/x3_base_package.dart';
import 'package:x3_business_core/business_clerk/business_clerk_details.dart';

class BusinessDepotClerkItem extends StatelessWidget {
  final Map<String, dynamic> item;

  BusinessDepotClerkItem({Key key, @required this.item}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BaseCardComponent(onTap: jumpBusinessClerkDetails, child: _buildUserWidget(context));
  }

  Widget _buildUserWidget(BuildContext context) {
    String userName = BaseUtils.getKeyData(this.item, 'userName').toString();
    String userImg = BaseUtils.getKeyData(this.item, 'userImg').toString();
    return Row(
      children: [
        BaseImageComponent(key: UniqueKey(), imageUrl: userImg, placeholderName: userName, width: 56.0, height: 56.0, type: BaseImageTypeEnum.X3User, size: BaseImageSizeEnum.original, circular: 56.0, fit: BoxFit.cover),
        SizedBox(width: 12.0),
        Expanded(child: _buildUserContentWidget(context)),
      ],
    );
  }

  Widget _buildUserContentWidget(BuildContext context) {
    String userName = BaseUtils.getKeyData(this.item, 'userName').toString();
    String userMobile = BaseUtils.getKeyData(this.item, 'userMobile').toString();
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        BaseComponentUtils.buildTextSpanWidget(['姓名:', userName]),
        SizedBox(height: 4.0),
        DefaultTextStyle(style: BaseStyles.subtitle2(context), child: BaseComponentUtils.buildTextSpanWidget(['手机号:', userMobile])),
      ],
    );
  }

  void jumpBusinessClerkDetails() {
    String userId = BaseUtils.getKeyData(this.item, 'userId').toString();
    BaseRouterUtil.getInstance().pushNamed(BusinessClerkDetails.sName, arguments: {'userId': userId});
  }
}
